﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
    <title>易得桌面</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageStyles" runat="server">
    <style type="text/css">
        .text
        {
            width: 230px;
        }
        .entryExplanation
        {
            font-weight: bolder;
            font-size: 14px;
            background-color: #FFEC8B;
            display: inline;
        }
        .resend_recover
        {
            border: 1px solid #CCCCCC;
            margin-bottom: 15px;
            margin-top: 10px;
            padding: 10px;
            width: 460px;
        }
        .avatar
        {
            float: left;
            margin-right: 10px;
            padding: 10px;
            text-align: center;
            width: 55px;
            background: none repeat scroll 0 0 #EEEEEE;
        }
        .entryExplanation
        {
            font-weight: bolder;
            font-size: 14px;
            background-color: #FFEC8B;
            display: inline;
        }
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageScripts" runat="server">
    <script type="text/javascript">
    //************* URL常量

    var URL_UPDATE_STAFF_INFO = '/Staff/DoUpdateStaffInfo';

    //************* 全局变量

    var g_Var = {
        "dataStorage": null
};
var StaticResource = {};

//************* 常量定义


//************* Accessor访问器
var EzAccessor = {};

function CreateAccessor() {
    if (ezmock.IS_MOCKED) {
        EzAccessor = CreateMockEzAccessor();

    } else {
        EzAccessor = CreateRealEzAccessor();
    }
}


function CreateMockEzAccessor() {
    //模拟实现服务器交互方法

    var mockEzAccessor = {

};

return mockEzAccessor;
}

function CreateRealEzAccessor() {
    //实现服务器交互方法
    var realEzAccessor = {
        "getStaffInfo": function () {
            return <%= ViewData["StaffInfo"]%>;
        },
        "getDeptList" : function (){
            return  <%= ViewData["DeptList"]%>;
        },
        "doUpdateStaffInfo": function (name, deptId, userName, pwd, mobileNo, qqNumber, mainEmail){
            $(document).ajaxBusy('begin');
            $.post(
                URL_UPDATE_STAFF_INFO,
                {   'name': name,
                    'deptId': deptId,
                    'userName': userName,
                    'pwd': pwd,
                    'mobileNo': mobileNo,
                    'qqNumber': qqNumber,
                    'mainEmail': mainEmail
                },
                function (e) {
                    $(document).ajaxBusy('end');
                    $.displayStatusInfo(e);
                }
            );   
        }
    };
    return realEzAccessor;
}


//存储数据
function getStoreData() {
    var dataStorage = [];

    var name = $('#txtName').val();
    var userName = $('#txtUserName').val();
    var deptId = $('#cmbDept').val();
    var qqNumber = $('#txtQq').val(); 
    var mobileNo =  $('#txtMobile').val();
    var email = $('#txtEmail').val();
    var pwd = $('#txtNewPwd').val();
    //存储
    dataStorage.push(name,
                     userName,
                     deptId,
                     qqNumber,
                     mobileNo,
                     email,
                     pwd);

    return dataStorage;
} 



//绑定个人信息
function bindStaffInfo(staffInfo){
    var name = staffInfo.TargetUser.Name;
    var userName = staffInfo.TargetUser.UserName;
    var deptId = staffInfo.TargetUser.Dept.Id;
    var qqNumber= staffInfo.ContactInfo.QqNumber;
    var mobile = staffInfo.ContactInfo.MobileNo;
    var email =  staffInfo.ContactInfo.MainEmail;
    //todo:Hr

    $('#txtName').val(name);
    $('#cmbDept').val(deptId);
    $('#txtUserName').val(userName);
    $('#txtMobile').val(mobile);
    $('#txtQq').val(qqNumber);  
    $('#txtEmail').val(email);

    //头像获取
    $('#imgAvatar').attr('src', "/core/headicon/" + staffInfo.TargetUser.Id);
    
}


function getDeptListForArray(deptList) {
    var deptListForArray = [];
    for (var key in deptList) {
        var name = deptList[key].DeptName;
        var id = deptList[key].Id;

        deptListForArray.push({ 'text': name,
            'value': id
        });
    }
    return deptListForArray;
}


//绑定部门列表
function bindDeptList(deptList) {

    var deptListForArray = getDeptListForArray(deptList);

    $('#cmbDept')
        .comboxBinding(deptListForArray, 'text', 'value');
}



//初始化页面
function initPage() {
    CreateAccessor();
    var staffInfo = EzAccessor.getStaffInfo();
    var deptList = EzAccessor.getDeptList();

    bindDeptList(deptList);
    bindStaffInfo(staffInfo);
   
    //保存数据
     g_Var["dataStorage"] = getStoreData();

}


//数据恢复
function recoverData(){
    var name = g_Var.dataStorage[0];
    var userName = g_Var.dataStorage[1];
    var deptId = g_Var.dataStorage[2];
    var qqNumber = g_Var.dataStorage[3];
    var mobile = g_Var.dataStorage[4];
    var email = g_Var.dataStorage[5];

    $('#txtName').val(name);
    $('#cmbDept').val(deptId);
    $('#txtUserName').val(userName);
    $('#txtMobile').val(mobile);
    $('#txtQq').val(qqNumber);  
    $('#txtEmail').val(email);
    //清空密码
    $('#txtNewPwd').clearFields();
    $('#txtPwdConfirm').clearFields();
}

//判断内容是否为空
function IsValueEmpty(dom, str){
	if($(dom).val() == ""){
		return true;
	}
	return false;
}


//检验密码是否一致 
function checkSameForpwd(){
    var isSame = false;
    var pwd = $('#txtNewPwd').val();
    var comfirmpwd = $('#txtPwdConfirm').val();

    if(pwd == comfirmpwd){
        isSame = true;
    }

    return isSame;
}



//初始化事件
function initPageEvent() {
    
    $('#btnSubmitBasicInfo').click( function (){
        //判空
        var isNameEmpty = IsValueEmpty($('#txtName'));

        if(isNameEmpty){
            var statusInfo = { 'Status': 'Error', 'Info': '姓名不能为空!', 'Date': null };
            $.displayStatusInfo(statusInfo); 
            return;
        }

        $(document).ajaxBusy('begin');
        $('#formBasicInfo').ajaxSubmit({
            data: {
                userId: EzAccessor.getStaffInfo().TargetUser.Id
            },
            success: function (statusInfo) {
                $.displayStatusInfo(statusInfo);
                $(document).ajaxBusy('end');

                g_Var["dataStorage"] = getStoreData();
                }
            });
    });
    $('#btnSubmitPwd').click( function (){
        if (!checkSameForpwd()){
            var statusInfo = { 'Status': 'Error', 'Info': '两次输入密码不一致!', 'Date': null };
            $.displayStatusInfo(statusInfo);
            return;
        }

        $(document).ajaxBusy('begin');
        $('#formPwd').ajaxSubmit({
            data: {
                userId: EzAccessor.getStaffInfo().TargetUser.Id
            },
            success: function (statusInfo) {
                $.displayStatusInfo(statusInfo);
                $(document).ajaxBusy('end');
                g_Var["dataStorage"] = getStoreData();
                }
            });
    });


    $('#btnSubmitContactInfo').click( function (){
        $(document).ajaxBusy('begin');
        $('#formContactInfo').ajaxSubmit({
            data: {
                userId: EzAccessor.getStaffInfo().TargetUser.Id
            },
            success: function (statusInfo) {
                $.displayStatusInfo(statusInfo);
                $(document).ajaxBusy('end');
                g_Var["dataStorage"] = getStoreData();
                }
            });
    });

     $('#btnRecover').click(function () {
            //恢复数据
            recoverData();
        });
}

$(function () {
    initPage();
    initPageEvent();


});

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PageHead" runat="server">
    <%
        Html.RenderPartial("_sayHello"); %>
    <div id="status-bar"><% Html.RenderPartial("_navigateTo"); %></div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageContent" runat="server">
    <div id="page-head">
        <img src="../../Content/icons/edit_user.png" style="width: 48px; height: 48px;" alt="edit" />
        <span>修改员工信息</span>
    </div>
    <div id="page-body" style="overflow: hidden;">
        <div class="resend_recover">
            <h3>
                我可以做些什么?</h3>
            <p style="font: 12px;">
                您可以修改员工的基本上信息：姓名，部门；也可以修改员工的登陆名和密码；以及联系方式。</p>
        </div>
        <div class="editMemberInfo">
            <div class="avatar">
                <img id="imgAvatar" width="48" height="48" src="" alt="" />
                <div class="linkChange">
                    <a class="admin">修改头像</a>
                </div>
            </div>
            
            <div style="margin-left: 100px; width: 380px;">
                <form id="formBasicInfo" action="DoUpdateBasicInfo" method="post">
                <div class="content-section">
                    <p class="entryExplanation">
                        基本信息</p>
                    <div class="formBox">
                        <ul class="fieldslist">
                            <li>
                                <div class="l">
                                    <label>
                                        姓名：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtName" name="name" class="text" />
                                </div>
                            </li>
                            <li>
                                <div class="l">
                                    <label>
                                        部门：
                                    </label>
                                </div>
                                <div class="r">
                                    <select id="cmbDept" style="padding: 2px;" name="deptId" value="选择部门" class="text">
                                    </select>
                                </div>
                            </li>
                        </ul>
                        <a style="float: right;" id="btnSubmitBasicInfo">修改基本信息</a>
                    </div>
                </div>
                </form>
                <form id="formPwd" action="DoUpdatePwd" method="post">
                <div class="content-section">
                    <p class="entryExplanation">
                        登录信息
                    </p>
                    <div class="formBox">
                        <ul class="fieldslist">
                            <li>
                                <div class="l">
                                    <label>
                                        用户名：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtUserName" readonly="readonly" class="text" />
                                </div>
                            </li>
                            <!--
                            <li>
                                <div class="l">
                                    <label>
                                        原密码：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtOldPwd" name="oldPassword" type="password" class="text" />
                                </div>
                            </li>
                            <li>
                                <div class="l">
                                    <label>
                                        新的密码：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtNewPwd" name="newPassword" type="password" class="text" />
                                </div>
                            </li>
                            <li>
                                <div class="l">
                                    <label>
                                        确认密码：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtPwdConfirm" type="password" class="text" />
                                </div>
                            </li>
                            -->
                        </ul>
                        <!--<a id="btnSubmitPwd" style="float: right;">修改密码</a>-->
                    </div>
                    
                </div>
                </form>
                <form id="formContactInfo" action="doUpdateContactInfo" method="post">
                <div class="content-section">
                    <p class="entryExplanation">
                        通讯方式
                    </p>
                    <div class="formBox">
                        <ul class="fieldslist">
                            <li>
                                <div class="l">
                                    <label>
                                        电话：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtMobile" name="mobileNo" class="text" />
                                </div>
                            </li>
                            <li>
                                <div class="l">
                                    <label>
                                        邮箱：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtEmail" name="mainEmail" class="text" />
                                </div>
                            </li>
                            <li>
                                <div class="l">
                                    <label>
                                        QQ：
                                    </label>
                                </div>
                                <div class="r">
                                    <input id="txtQq" name="qqNumber" class="text" />
                                </div>
                            </li>
                        </ul>
                        <a id="btnSubmitContactInfo" style="float: right;">修改联系方式</a>
                    </div>
                    
                </div>
                </form>
                <!--
                        <div class="content-section">
                        <p class="entryExplanation">
                            公司角色
                        </p>
                        <div class="formBox">
                            <label id="lblChecked" for="isHR">
                                <input type="checkbox" id="isHR" />是的，我确定赐予该用户神圣的HR身份！</label>
                        </div>
                        !-->
            </div>
            </form>
        </div>

</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="PageShortcut" runat="server">
    <div id="shortcuts" class="box">
    </div>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="PageFoot" runat="server">
    <div id="tip_alert" style="display: none;">
    </div>
</asp:Content>
